﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Azad.BCL;
using System.Web.UI.HtmlControls;
using Azad;
using System.Collections.Specialized;
using NazSoft.Framework;

public partial class MasterPage : System.Web.UI.MasterPage
{
    //private NameValueCollection dateInfo = null;
    DateTime? today = null;

    protected void Page_Load(object sender, EventArgs e)
    {

        //if (Request.AppRelativeCurrentExecutionFilePath.ToLowerInvariant().Contains("error.aspx"))
        //{
        //    return;
        //}

        //SilverlightService silverlightService = new SilverlightService();
        //BindSlider();
        //if (!IsPostBack)
        //{

        //    if (Request.QueryString["mag"] == "true")
        //    {
        //        MagnifyGlass.Text = "OFF";
        //        MagnifyGlass.NavigateUrl = "?mag=false";
        //        Session["Magni"] = "tim";

        //        string query = "jQuery(document).ready(function ($) { $('#" + imgFarman.ClientID +
        //                       "').addpowerzoom({defaultpower: 1.4," +
        //                       "powerrange: [80, 80],largeimage: true,magnifiersize: [500, 200] }) });";
        //        //query = string.Format(query, imgFarman.ClientID);
        //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Farman", query, true);

        //    }
        //    else
        //    {
        //        if (Request.QueryString["mag"] == "false")
        //        {
        //            Session["Magni"] = null;
        //        }

        //        if (!string.IsNullOrEmpty(Convert.ToString(Session["Magni"])))
        //        {
        //            MagnifyGlass.Text = "OFF";
        //            MagnifyGlass.NavigateUrl = "?mag=false";

        //            string query = "jQuery(document).ready(function ($) { $('#" + imgFarman.ClientID +
        //                           "').addpowerzoom({defaultpower: 1.4," +
        //                           "powerrange: [80, 80],largeimage: true,magnifiersize: [500, 200] }) });";
        //            //query = string.Format(query, imgFarman.ClientID);
        //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Farman", query, true);
        //        }
        //        else
        //        {

        //            MagnifyGlass.Text = "ON";
        //            MagnifyGlass.NavigateUrl = "?mag=true";
        //        }
        //    }
        //    // create service object 



        //    bool preview = Convert.ToBoolean(Request.QueryString["p"]);
        //    today = DateTimeUtilities.GetDateFromQueryString();
        //    var logoInfo = silverlightService.GetByCurrentId(today, preview);
        //    if (logoInfo != null)
        //    {
        //        imgFarman.ImageUrl = logoInfo.FarmanImage;
        //        Logo.ImageUrl = logoInfo.LogoImage;
        //        Heading.ImageUrl = logoInfo.HeaderImage;


        //        // over-ride date here to be used later in databound method
        //        today = logoInfo.CurrentDate;

        //        //dateInfo.Add("y", today.Value.Year.ToString());
        //        //dateInfo.Add("m", today.Value.Month.ToString());
        //        //dateInfo.Add("d", today.Value.Day.ToString());
        //    }
        //    else
        //    {
        //        imgFarman.Visible = false;
        //        Logo.Visible = false;
        //        Heading.Visible = false;


        //        return;
        //    }



        //    // get menu and then bind
        //    // do not move this code anywhere
        //    // becuase in the above code, the date is set
        //    // which is used in the databound method of this menu
        //    var menu = silverlightService.GetMenu();
        //    lstMenu.DataSource = menu.Where(x => x.LookUpID != 12).Where(c => c.LookUpID != 13);
        //    lstMenu.DataBind();

        //    //
        //    var navigateUrl = string.Format("/{0}/{1}/{2}/{3}", today.Value.Year, today.Value.Month.ZeroPad(), today.Value.Day.ZeroPad(), "aaj-ka-akhbar");
        //    Lnklogo.HRef = navigateUrl;
        //    LnkHeader.HRef = navigateUrl;
        //}
        //#region bind commercials
        //if (today.HasValue)
        //{
        //    var commercials = silverlightService.GetCommercial(today.Value);
        //    if (commercials != null)
        //    {
        //        foreach (var commercial in commercials)
        //        {
        //            switch (commercial.TypeId)
        //            {
        //                case 101:
        //                    {
        //                        CommercialVerticalLarge.InnerHtml = commercial.Script;
        //                    }
        //                    break;
        //                case 102:
        //                    {
        //                        CommercialLeftVertical1.InnerHtml = commercial.Script;
        //                    }
        //                    break;
        //                case 103:
        //                    {
        //                        CommercialLeftVertical2.InnerHtml = commercial.Script;
        //                    }
        //                    break;
        //                case 104:
        //                    {
        //                        CommercialRightVertical1.InnerHtml = commercial.Script;
        //                    }
        //                    break;
        //                case 105:
        //                    {
        //                        CommercialRightVertical2.InnerHtml = commercial.Script;
        //                    }
        //                    break;
        //                case 106:
        //                    {
        //                        CommercialBottomHorizontal.InnerHtml = commercial.Script;
        //                    }
        //                    break;
        //                default:
        //                    break;
        //            }
        //        }
        //    }
        //}
        //#endregion


    }

    private void BindSlider()
    {
        var collection = Request.QueryString;
        String mn = collection["mn"] ?? "taza-tareen"; // menu name
        string mp = collection["mp"];
        bool preview = Convert.ToBoolean(collection["preview"]);
        SilverlightService silverlightService = new SilverlightService();
        var today = DateTimeUtilities.GetLogoDateFromQueryString(collection);

        var logoInfo = silverlightService.GetByCurrentId(today, preview);
        if (logoInfo != null)
        {
            var details = logoInfo.Detail.Where(x => x.MenuId == 13).FirstOrDefault();
            if (details != null)
            {
                Repeater1.DataSource = details.DetailToDetail;
                Repeater1.DataBind();
            }
        }
    }
    protected void lstMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            var lookup = (BCL.Entity.LookUp)e.Item.DataItem;
            if (lookup != null)
            {
                var newsTypeHyperlink = (HtmlAnchor)e.Item.FindControl("NewsTypeHyperlink");
                if (newsTypeHyperlink != null)
                {
                    string menuName = lookup.Description;



                    //var today = DateTimeUtilities.GetDateFromQueryString();
                    if (today.HasValue)
                    {
                        var navigateUrl = string.Format("/{0}/{1}/{2}/{3}", today.Value.Year, today.Value.Month.ZeroPad(), today.Value.Day.ZeroPad(), menuName);
                        newsTypeHyperlink.HRef = navigateUrl;
                    }

                    if (lookup.LookUpID == 11)
                    {
                        newsTypeHyperlink.Target = "_blank";
                        newsTypeHyperlink.HRef = newsTypeHyperlink.HRef + "?mp=b";
                    }
                }
            }
        }
    }
    protected void lblglass_Click(object sender, EventArgs e)
    {
        //if (lblglass.Text == "OFF")
        //{
        //    Session["Magni"] = null;
        //    lblglass.Text = "ON";
        //}
        //else
        //{
        //    Session["Magni"] = "tim";
        //    lblglass.Text = "OFF";
        //    lblglass.Text = "OFF";

        //    //string query = "jQuery(document).ready(function ($) { $('#" + imgFarman.ClientID + "').addpowerzoom({defaultpower: 1.4," +
        //    //               "powerrange: [80, 80],largeimage: true,magnifiersize: [500, 200] }) });";
        //    ////query = string.Format(query, imgFarman.ClientID);
        //    //ScriptManager.RegisterStartupScript(this, this.GetType(), "Farman", query, true);

        //}


        //Response.Redirect(Request.Url.AbsoluteUri);
    }
}
